package com.yan_jiu_sheng.daily.AC;

import java.util.HashSet;

/**
 * https://leetcode.cn/problems/minimum-operations-to-make-a-special-number/?envType=daily-question&envId=2024-07-25
 *
 * @author yulongtian
 * @create 2024-07-25 13:01
 */
public class Test20240725 {
    public static void main(String[] args) {
        System.out.println(new Test20240725().minimumOperations("10"));
    }

    public int minimumOperations(String num) {
        HashSet<Integer> set = new HashSet<>(4);
        set.add(0);
        set.add(25);
        set.add(50);
        set.add(75);
        char[] chs = num.toCharArray();
        int ans = Integer.MAX_VALUE;
        for (int j = 0; j < chs.length; j++) {
            for (int i = 0; i < j; i++) {
                if (set.contains((chs[i] - '0') * 10 + chs[j] - '0')) {
                    ans = Math.min(ans, chs.length - i - 2);
                }
            }
        }
        if (ans == Integer.MAX_VALUE) {
            // 计算不为0的个数
            int temp = 0;
            for (char ch : chs) {
                if (ch != '0') {
                    temp++;
                }
            }
            return temp;
        }

        return ans;
    }
}
